package ioc

import (
	"fmt"

	"google.golang.org/grpc"
)

func (app *Container) SetGrpc(obj GrpcIocObj) {
	app.grpcs[obj.Name()] = obj
}
func (app *Container) GetGrpc(name string) GrpcIocObj {
	v, ok := app.grpcs[name]
	if !ok {
		panic(fmt.Sprintf("grpc not found: %s", name))
	}
	return v
}

func (app *Container) InitGrpc(s *grpc.Server) error {
	for _, v := range app.grpcs {
		if err := v.Init(); err != nil {
			return err
		}
		v.Register(s)
	}
	return nil
}
